/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package stuff;

import java.awt.Component;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.TreeMap;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import model.Diagnose;

/**
 *
 * @author JArik
 */
public class TableButtonRenderer extends JButton
            implements TableCellRenderer{

    TreeMap pressed;
    private Object mValue;
     public TableButtonRenderer(String name,TreeMap pr) {
        super();
        this.setText(name);
        pressed = pr;
        this.setEnabled(true);
        this.setMargin(new Insets(3,1,3,1));
        final TableButtonRenderer tbr = this;
     }
     public TableButtonRenderer(String name) {
        super();
        this.setText(name);
        this.setEnabled(true);
        this.setMargin(new Insets(3,1,3,1));
        final TableButtonRenderer tbr = this;
     }
     public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus, int row, int column) {

         this.setEnabled(true);
         if (isSelected) {
           setForeground(table.getSelectionForeground());
           super.setBackground(table.getSelectionBackground());

         } else {
           setForeground(table.getForeground());
           setBackground(table.getBackground());
         }
         mValue = value;
         if(value != null && pressed != null)
         if(!pressed.containsKey(value.toString()))
             if(((Diagnose)value).isPredv())
               pressed.put(value.toString(), false);
             else
             {
               pressed.put(value.toString(), true);
               this.setEnabled(false);
               //System.out.println("Here2");
             }
         else
             if((Boolean)pressed.get(value.toString()) == true || !((Diagnose)value).isPredv())
             {
                 this.setSelected(false);
                 this.setEnabled(false);
                 //System.out.println("Here");
             } else
             {
                 this.setSelected(false);
                 this.setEnabled(true);
             }
         //System.out.println("Renderer-Enb: "+this.isEnabled());
         return this;
      }

}
